home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power Programmierung
/
Power-Programmierung (Tewi)(1994).iso
/
mutt
/
textmode.mut
< prev
next >
Wrap
Text File
|
1988-10-11
|
6KB
|
233 lines
;; textmode.mut : An electric text mode.
;; C Durland
;; You will notice a lack of anything to do with sentences, outlining and
;; other useful text mode things.
(const
fill-column 72 ; Column to word wrap at (0 means no wrapping)
tab-size 0 ; Tab size (0 means use the TAB character)
)
(defun
text-mode
{
(word-wrap fill-column)(tab-stops tab-size)
(bind-local-key "newline-and-indent" "C-M")
(bind-local-key "adjust-block" "M-J")
(bind-local-key "center-line" "M-S")
(bind-local-key "backward-paragraph" "M-a")
(bind-local-key "forward-paragraph" "M-e")
(bind-local-key "mark-paragraph" "M-h")
}
)
(include me.h)
(include wspace.mut)
(defun
center-line ; Center line the cursor is on. With arg, centers n lines.
{
(int n width wrap-col)
(beginning-of-line)
(if (== (wrap-col (word-wrap)) 0) (wrap-col (screen-width)))
(for (n (arg-prefix)) (< 0 n) (-= n 1)
{
(kill-whitespace)
(end-of-line)(width (current-column))(beginning-of-line)
(to-col (/ (+ 1 (- wrap-col width)) 2))
(forward-line 1) ; move to the next line
})
}
center-region ; Center all the lines in a region.
{
(byte type)(int left-edge width height)(INT size)
(region-stats (loc type))
(if (== type MARK-ABOVE-DOT)(exchange-dot-and-mark))
(arg-prefix height)(center-line)
}
;; Format a block of lines - those lines between the dot and mark
;; inclusive.
;; Formats the block ragged right. With argument, justifies.
;; See adjust.mut for details.
adjust-block
{
(byte type)(int left-edge width height)(INT size)
(region-stats (loc type))
(if (== type MARK-ABOVE-DOT)(exchange-dot-and-mark))
(msg "Formatting ...")
(adjust-lines height
(if (== 0 (word-wrap)) fill-column (word-wrap))
(arg-flag))
(msg "Formatted.")
}
)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;; Paragraphs ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(const
between-paragraphs 0
at-start-of-paragraph 1
on-first-line-of-paragraph 2
in-paragraph 3
on-last-line-of-paragraph 4
at-end-of-paragraph 5
)
;; Move forward to end of paragraph. With arg, do it arg times.
;; If at end of paragraph, move to the end of the next one.
(defun
forward-paragraph
{
(int col)
(switch (where-in-paragraph)
between-paragraphs
{
(label above-paragraph)
(skip-forward-blank-lines)
(forward-line 1) ;; skip over first line of paragraph
(if (looking-at '\ *$') { (forward-line -1)(end-of-line)(done) })
}
at-start-of-paragraph ;; skip over first line of paragraph
(forward-line 1)
on-first-line-of-paragraph ;; skip over first line of paragraph
(forward-line 1)
on-last-line-of-paragraph { (end-of-line)(done) }
at-end-of-paragraph { (forward-line 1)(goto above-paragraph) }
)
(col (get-indent))
(while TRUE
{
(if (not (forward-line 1)) (break)) ;; at end of buffer
(if (looking-at '\ *$') { (forward-line -1)(break) })
(skip-whitespace)
(if (!= col (current-column)) { (forward-line -1)(break) })
})
(end-of-line)
}
)
;; Move backward to start of paragraph. With arg, do it arg times.
;; If at start of paragraph, move to start of the one above.
(defun
backward-paragraph
{
(int col)
(switch (where-in-paragraph)
between-paragraphs (skip-backward-blank-lines)
at-start-of-paragraph
{ (forward-line -1)(skip-backward-blank-lines) }
on-first-line-of-paragraph { (beginning-of-line) (done) }
)
(col (get-indent))
(while TRUE
{
(if (not (forward-line -1)) (break)) ;; top of buffer
(if (looking-at '\ *$') { (forward-line 1)(break) })
(skip-whitespace)
(if (!= col (current-column)) (break) )
})
(beginning-of-line)
}
)
(defun
;; Put mark at beginning of this paragraph, point at end.
;; If between paragraphs, mark the next one.
mark-paragraph
{
(forward-paragraph)
(set-mark)
(backward-paragraph)
(exchange-dot-and-mark)
(msg "Paragraph marked")
}
kill-paragraph ;; Kill to end of paragraph.
{
(set-mark)(forward-paragraph)(kill-region)
}
backward-kill-paragraph ;; Kill back to start of paragraph.
{
(set-mark)(backward-paragraph)(kill-region)
}
)
(defun
where-in-paragraph HIDDEN
{
(int above below dastart col)
(col (current-column))
(beginning-of-line)
(if (looking-at '\ *$') { between-paragraphs (done) })
;; looking at text
(dastart (get-indent))
;; look at the line above
(if (not (forward-line -1))
{
(label on-first-line-of-paragraph)
(if (== col 1) at-start-of-paragraph on-first-line-of-paragraph)
(done)
})
(if (looking-at '\ *$')
{ (forward-line 1) (goto on-first-line-of-paragraph) })
(above (get-indent))
;; look at the following line
(if (forward-line 2)
{
(if (looking-at '\ *$')
{
(forward-line -1)
(label on-last-line-of-paragraph)
(end-of-line)
(if (== col (current-column))
at-end-of-paragraph on-last-line-of-paragraph)
(done)
}
{
(below (get-indent))
(forward-line -1) ;; move point back to where it started
(if (== above below)
{
(if (!= above dastart) (goto on-first-line-of-paragraph))
}
{ ;; above != below
(if (== above dastart) (goto on-last-line-of-paragraph))
(if (!= above dastart) (goto on-first-line-of-paragraph))
})
})
})
in-paragraph
}
)
(defun
skip-forward-blank-lines HIDDEN
{
(beginning-of-line)
(while (and (looking-at '\ *$') (forward-line 1)) ())
}
skip-backward-blank-lines HIDDEN
{
(beginning-of-line)
(while (and (looking-at '\ *$') (forward-line -1)) ())
}
get-indent HIDDEN
{ (beginning-of-line) (skip-whitespace) (current-column) }
)